//
//  HXCategoryDetailVC.m
//  ZCooking
//
//  Created by 韩旭 on 16/9/20.
//  Copyright © 2016年 HX_. All rights reserved.
//

#import "HXCategoryDetailVC.h"
#import "HX_Macro.h"
#import "HXCategoryDetaiilCell.h"
#import "HXCategoryModel.h"
#import "HXCategoryDataModel.h"

@interface HXCategoryDetailVC ()<UITableViewDataSource, UITableViewDelegate>
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) NSMutableArray *arrAll;
@property (nonatomic, strong) UIView *searchView;
@end

@implementation HXCategoryDetailVC
- (NSMutableArray *)arrAll {
    if (!_arrAll) {
        _arrAll = [NSMutableArray array];
    }
    return _arrAll;
}
- (UITableView *)tableView {
    if (!_tableView) {
        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT - 64) style:0];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        self.tableView.tableHeaderView = self.searchView;
        [_tableView registerNib:[UINib nibWithNibName:@"HXCategoryDetaiilCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"HXCategoryDetaiilCell"];
    }
    return _tableView;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    [self getNetWorking:self.netId];
    [self.view addSubview:self.tableView];
}
- (void)creatHeaderView {
    self.searchView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 64)];
    _searchView.backgroundColor = [UIColor redColor];
    [self.view addSubview:self.searchView];
}
- (void)getNetWorking:(NSString *)netId {
    NSString *url = @"http://api.izhangchu.com/";
    NSString *body = [NSString stringWithFormat:@"cat_id=%@&type=1&page=1&methodName=CategorySearch&size=20&version=4.40&", netId];
    NSDictionary *dicHeader = @{};
    [HXNetTool postNetWithUrl:url body:body BodyStyle:HXBodyString Header:dicHeader Response:HXJSON Success:^(id result) {
        NSDictionary *results = result;
        NSDictionary *dicData = results[@"data"];
        HXCategoryModel *category = [HXCategoryModel ModelWithDic:dicData];
        [self.arrAll addObject:category];
        [_tableView reloadData];
    } Failure:^(NSError *error) {
    }];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    HXCategoryModel *category = [self.arrAll firstObject];
    return category.data.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    HXCategoryDetaiilCell *cell = [tableView dequeueReusableCellWithIdentifier:@"HXCategoryDetaiilCell"];
    HXCategoryModel *category = [self.arrAll firstObject];
    HXCategoryDataModel *detailModel =category.data[indexPath.row];
    cell.arrBtn = [detailModel.tags_info mutableCopy];
    cell.detailModel = detailModel;
    cell.backgroundColor = [UIColor whiteColor];
    return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 250;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
